
var urlBK = "https://broker.bankinter.com/www/es-es/cgi/broker+valores_indice+ajax?mercado=xxxx&isin=nnnn";
var xPath = "/root/content/INDEX/STOCKS/STOCK";


var DOCKED_WIDTH = 119;
var DOCKED_HEIGHT = 150;

var UNDOCKED_WIDTH = 598; //300;
var UNDOCKED_HEIGHT = 376; //175;
var DEFAULT_REFRESH = 5000;

var treemap = null; 

///

///
function processDockEvent()
{ 
    genDocked();
}

///
function processUndockEvent()
{
    genUndocked();   
}

///
function refreshTreemap(docked)
{
    readUserSettings();
    
    var merc = mercado.split(" ");
    
    var aux = urlBK;
    aux = aux.replace("nnnn", merc[0]);
    aux = aux.replace("xxxx", merc[1]);
    
    if (treemap == null)
    {
        treemap = new Bankinter.Graphics.XmlTreemap("tree_root", DOCKED_WIDTH, DOCKED_HEIGHT, aux, xPath, 5000);
    }
    
    treemap.setDataUrl(aux);
    treemap.startLoad(true);
    treemap.setColorRange(color_ascenso, color_descenso);
    treemap.setRefreshInterval(parseInt(refresco, 10) * 60000);
    treemap.setBrightness(parseInt(brillo, 10));
    
    if ("true" == mostrar_bordes) 
        treemap.showBorder(true);
    else
        treemap.showBorder(false);
    
    if (docked)
    {
        treemap.showTitle(false);
        treemap.displayTreeMap(DOCKED_WIDTH, DOCKED_HEIGHT); 
        treemap.setAllowTreetree(false);
    }
    else
    {
        if ("true" == mostrar_nombres) 
            treemap.showTitle(true);
        else
            treemap.showTitle(false);
        treemap.displayTreeMap(UNDOCKED_WIDTH, UNDOCKED_HEIGHT);
        treemap.setAllowTreetree(true);
    }
    
    document.getElementById("footter").innerText = merc[0];
}

///
function genDocked()
{   
    document.body.style.width = "130px";                                            
    document.body.style.height = "200px";  
    
    document.getElementById("gadgetMainFrame").style.width = "120px";                                          
    document.getElementById("gadgetMainFrame").style.height = "190px";                                         
    
    document.getElementById("gadgetContentFrame").style.width = "120px";                                       
    document.getElementById("gadgetContentFrame").style.height = "190px";   

    try
    {
        System.Gadget.background="url(images/backgnd_130X200.png)";  
    }
    catch(e) {}
    
    document.getElementById("bannerDocked").style.width = "120px";
    document.getElementById("bannerDocked").style.height = "20px";
    document.getElementById("bannerDocked").style.top = "0px";
    document.getElementById("bannerDocked").style.left = "0px"; 
    
    document.getElementById("tree_root").style.top = "20px";                                                           

    document.getElementById("footter").style.width = "120px";
    document.getElementById("footter").style.height = "10px";
    document.getElementById("footter").style.top = "170px";
    document.getElementById("footter").style.left = "0px";
    
    document.getElementById("bannerDocked").style.visibility = "visible";
    document.getElementById("bannerUndocked").style.visibility = "hidden";
     
    refreshTreemap(true); 
}

///
function genUndocked()
{  
    document.body.style.width = "610px";                                            
    document.body.style.height = "430px";
    
    document.getElementById("gadgetMainFrame").style.width = "600px";                                          
    document.getElementById("gadgetMainFrame").style.height = "420px";                                         
    
    document.getElementById("gadgetContentFrame").style.width = "600px";                                       
    document.getElementById("gadgetContentFrame").style.height = "420px";  
    
    try
    {
        System.Gadget.background="url(images/backgnd_610X430.png)";
    }
    catch(e)
    {
    }
    
    //System.Gadget.background="url(images/backgnd.png)";                                                  
                       
    document.getElementById("bannerUndocked").style.width = "120px";
    document.getElementById("bannerUndocked").style.height = "20px";
    document.getElementById("bannerUndocked").style.top = "0px";
    document.getElementById("bannerUndocked").style.left = "0px"; 
    
    document.getElementById("tree_root").style.top = "25px";  
    
    document.getElementById("footter").style.width = "120px";
    document.getElementById("footter").style.height = "10px";
    document.getElementById("footter").style.top = "404px";
    document.getElementById("footter").style.left = "0px";
    
    document.getElementById("bannerDocked").style.visibility = "hidden";
    document.getElementById("bannerUndocked").style.visibility = "visible";
    
    refreshTreemap(false);                                                                   
}

function processSettingsClosedEvent(event)
{
   if (event.closeAction == event.Action.commit) {
       loadMain();
   }
}

/// 
function loadMain() 
{   
    try
    {
        readUserSettings();
        
        System.Gadget.onDock = processDockEvent;                                   
        System.Gadget.onUndock = processUndockEvent;                              

        System.Gadget.Flyout.file = "flyout.htm";                              
        
        System.Gadget.settingsUI = "settings.htm"; 
                                     
        System.Gadget.onSettingsClosed = processSettingsClosedEvent;               
    }
    catch(e)
    {
    }


    try
    {
        if (System.Gadget.docked) 
            genDocked();
        else 
            genUndocked();
    }
    catch(e)
    {
        genUndocked();
        //genDocked();
    }
}



